import { flatArrayFun } from "@/utils/array";
export default {
  props: {
    childrenKey: {
      type: String,
      default: 'attrChildArr'
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    children() {
      return this.node[this.childrenKey];
    },
    logicField() {
      return this.node.logicField;
    },
    logicVal: {
      set(value) {
        this.$set(this.node, this.logicField, value ? '1' : '0');
      },
      get() {
        return this.node[this.logicField] !== '0';
      }
    }
  },
  filters: {
    logicFilter(value) {
      return value ? '且' : '或';
    }
  },
  data() {
    return {
      cascaderProps: {
          label: 'name',
          value: 'code',
          expandTrigger: 'hover',
          disabled: 'disabled'
      }
    };
  },
  methods: {
    clone(obj) {
      let data = null;
      try {
        data = JSON.parse(JSON.stringify(obj));
      } catch (e) {
        //
      }
      return data;
    },
    addLeaf(node, uniqueData = this.uniqueChildData) {
      node[this.childrenKey].push(Object.assign({
        opeationList: [], // 操作列表
        multipleList: [], // 多选下拉列表
        property: [],
        condition: '', // 操作条件值
        valArray: [], // 下拉框的值 多选框
        valArrayName: '', // 多选组件返回的name值
        transferRightValueObj: {} // 多选组件穿梭框右侧 通过key显示value
      }, this.clone(uniqueData)));
    },
    getsqlTagType(val, code) {
      const flatArray = []
      const optionArray = this.cascaderOptions || this.userOptions || []
      flatArrayFun(optionArray, flatArray)
      if (val.includes('user_tag_group_header')) {
        const result = flatArray.find((flat) => code === flat.code);
        return result ? result.dataType : '';
      }
      return '';
    }
  }
};
